package qingke.hibernate.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.query.Query;

import qingke.hibernate.bean.College;


public class CollegeDao {
	private Session session;

	public CollegeDao(Session session) {
		this.session = session;
	}

	public List<College> list() {
		Query<College> query = session.createQuery("from College", College.class);

		return query.getResultList();
	}
	
	public void insert(College college){
		Transaction tx = session.beginTransaction();
		try{
			session.save(college);
			tx.commit();
		}catch(HibernateException e){
			e.printStackTrace();
			tx.rollback();
		}
	}
}
